package com.moto.service.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.google.common.collect.Lists;
import com.moto.entity.MotoUser;
import com.moto.enums.UserType;
import com.moto.repository.MotoUserRepository;
import com.moto.service.UserService;
import com.moto.util.DateUtils;

@Service("userService")
public class UserServiceImpl implements UserService {
	
	private static final Logger LOG = Logger.getLogger(UserServiceImpl.class);
	
	@Autowired
	private MotoUserRepository motoUserRepository;
	
	@Override
	public boolean locking(String userId) {
		LOG.debug("锁定用户，Id = "+userId);
		int locking = motoUserRepository.locking(userId);
		if(locking==1){
			return true;
		}else{
			return false;
		}
	}

	@Override
	public boolean deblocking(String userId) {
		LOG.debug("解锁用户，Id = "+userId);
		int deblocking = motoUserRepository.deblocking(userId);
		if(deblocking==1){
			return true;
		}else{
			return false;
		}
	}

	@Override
	public List<MotoUser> userList() {
		List<MotoUser> users= motoUserRepository.getAll();
		List<MotoUser> returnList = Lists.newArrayListWithExpectedSize(users.size());
		for (MotoUser motoUser : users) {
			motoUser.setUserRegisttime(
					DateUtils.TimeStamp2Date(Long.valueOf(motoUser.getUserRegisttime())));
			motoUser.setUserType(UserType.getTypeName(motoUser.getUserType()));
			//motoUser.setUserIsSeal(UserStatus.getStatus(motoUser.getUserIsSeal()));
			returnList.add(motoUser);
		}
		return returnList;
	}

}
